<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>15组件的注册</title>
</head>
<body>
<div id="app">
    <button-counter></button-counter>
    <button-counter></button-counter>
    <inner-button-counter01></inner-button-counter01>
    <inner-button-counter01></inner-button-counter01>
    <inner-button-counter02></inner-button-counter02>
    <inner-button-counter02></inner-button-counter02>
</div>
<script src="../vue.global.3.0.5.js"></script>
<script>
    //连缀写法
    //Vue.createApp({}).component("button-counter",{}).mount("#app");

    //创建局部组件(推荐)
    const innerButtonCounter02 = {
        data() {
            return {counter: 300}
        },
        template: `
            分离的内部组件计数器: {{counter}}
            <button v-on:click="counter++">counter++</button><br>
        `
    }

    //1、创建一个Vue应用实例，本身是最顶层的根组件
    const app = Vue.createApp({
        data() {
            return { }
        },
        //定义一个局部组件，本组件是根组件的子组件(推荐)
        components: {
            "inner-button-counter01": {
                data() {
                    return {counter: 200}
                },
                template: `
                    内部组件计算器: {{counter}}
                    <button v-on:click="counter++">counter++</button><br>
                `
            },
            "inner-button-counter02": innerButtonCounter02
        }
    });
    //2、定义一个全局组件
    app.component('button-counter', {
        //数据
        data() {
            return {counter: 100}
        },
        //模板
        template: `
            计算器: {{counter}}
            <button v-on:click="counter++">counter++</button><br>
        `   
    });
    //3、挂载
    const vm = app.mount("#app");
</script>
</body>
</html>